<template>
  <div class="container">
    <el-form :model="searchList" ref="searchList" size="normal">
      <el-row :gutter="20">
        <el-col :span="18" :offset="0">
          <el-form-item label="">
            <el-select v-model="searchList.module" value-key="module" placeholder="接口模块" clearable filterable
              class="wid">
              <el-option v-for="(item,index) in apiModule" :key="index"
                :label="item.center_key+' ('+item.center_code+') '" :value="index">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="0">
          <div class="right">
            <el-button type="primary" size="default" @click="search" :loading="loading">搜索</el-button>
            <el-button type="primary" size="default" @click="syncApis" :loading="loading">同步选中项</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data="tableData" border stripe :height="offsetHeight" v-loading="loading" ref="tableData" selection>
      <el-table-column type="selection" width="50" align="center"></el-table-column>
      <el-table-column type="index" label="排序" width="50" align="center"></el-table-column>
      <el-table-column prop="statusCodeCN" label="状态" width="100" align="center"></el-table-column>
      <el-table-column prop="funName" label="接口名称" align="center"></el-table-column>
      <el-table-column prop="id" label="接口标识" align="center"></el-table-column>
      <el-table-column prop="desc" label="描述" width="200" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="syncApi(row)" :loading="loading">同步</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>
<script>
export default {
  name: '',
  components: {

  },
  props: {

  },
  data () {
    return {
      apiModule: [],
      offsetHeight: document.documentElement.clientHeight - 210,
      loading: false,
      searchList: {},
      tableData: []
    }
  },
  created () {

  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      const res = await this.$http('sysApiDict', {
        requestType: 'get',
      })
      this.apiModule = res
    },
    async search () {
      this.loading = true
      const res = await this.$http('sysApiList', {
        requestType: 'get',
        center_code: this.apiModule[this.searchList.module].center_code,
        center_key: this.apiModule[this.searchList.module].center_key
      })
      this.tableData = res
      this.loading = false
    },
    syncApis () {
      if (this.$refs.tableData.selection.length < 1) {
        this.$tips.error('请选择至少一条')
      } else {
        this.onSync(this.$refs.tableData.selection)
      }
    },
    async syncApi (row) {
      let arr = []
      arr.push(row)
      this.onSync(arr)
    },
    async onSync (arr) {
      const res = await this.$http('sysApiUp', {
        list: arr
      })
      console.log(res);
      if (res.sucess) {
        this.$tips.success('成功' + res.sucess + '条，失败' + res.fail + '条')
      } else {
        this.$tips.error(res.errmsg)
      }
      this.search()
    }
  },
  computed: {

  }
}
</script>
<style lang='scss' scoped>
</style>
